//
//  KzMutableArray.swift
//  swifttest1
//
//  Created by kologe on 2024/9/17.
//
import Foundation
import Combine

class KzMutableArray<T>: ObservableObject {
    @Published var array: Array<T>
    @Published var state: Bool = false
    init(array: Array<T>) {
        self.array = array
    }
    func add(obj:T){
        array.append(obj)
    }
    func removeAllObjects(){
        array.removeAll()
    }
    func reverserArr() ->Array<T>{
        return Array(array.reversed())
    }
    
    func updateData(){
        objectWillChange.send()
    }
    subscript(index:Int) -> T{
        return array[index]
    }
    
    func forEach(_ body:@escaping( (_ element:T) -> Void) ){
        self.array.forEach { t in
            body(t)
        }
    }
}
